#include "Main.h"

Vector VectorScale(const Vector &v1, Vector &v2){
	Vector returnVector;
	returnVector.x = v1.x * v2.x;
	returnVector.y = v1.y * v2.y;
	returnVector.z = v1.z * v2.z;
	return returnVector;
}

Vector VectorScale(Vector &v1, const Vector &v2){
	Vector returnVector;
	returnVector.x = v1.x * v2.x;
	returnVector.y = v1.y * v2.y;
	returnVector.z = v1.z * v2.z;
	return returnVector;
}

Vector VectorScale(Vector &v1, Vector &v2){
	Vector returnVector;
	returnVector.x = v1.x * v2.x;
	returnVector.y = v1.y * v2.y;
	returnVector.z = v1.z * v2.z;
	return returnVector;
}

Vector VectorSubtraction(const Vector *v1, const Vector *v2){
	Vector returnVector;
	returnVector.x = v1->x - v2->x;
	returnVector.y = v1->y - v2->y;
	returnVector.z = v1->z - v2->z;
	return returnVector;
}

Vector VectorSubtraction(Vector *v1, Vector *v2){
	Vector returnVector;
	returnVector.x = v1->x - v2->x;
	returnVector.y = v1->y - v2->y;
	returnVector.z = v1->z - v2->z;
	return returnVector;
}

Vector VectorAddition(const Vector *v1, const Vector *v2){
	Vector returnVector;
	returnVector.x = v1->x + v2->x;
	returnVector.y = v1->y + v2->y;
	returnVector.z = v1->z + v2->z;
	return returnVector;
}

Vector VectorAddition(Vector *v1, Vector *v2){
	Vector returnVector;
	returnVector.x = v1->x + v2->x;
	returnVector.y = v1->y + v2->y;
	returnVector.z = v1->z + v2->z;
	return returnVector;
}

Vector VectorNegate(Vector *v1){
	Vector returnVector;
	returnVector.x = -v1->x;
	returnVector.y = -v1->y;
	returnVector.z = -v1->z;
	return returnVector;
}

Vector VectorMultiplication(const Vector *v1, float multiplier){
	Vector returnVector;
	returnVector.x = v1->x * multiplier;
	returnVector.y = v1->y * multiplier;
	returnVector.z = v1->z * multiplier;
	return returnVector;
}

Vector VectorMultiplication(Vector *v1, float multiplier){
	Vector returnVector;
	returnVector.x = v1->x * multiplier;
	returnVector.y = v1->y * multiplier;
	returnVector.z = v1->z * multiplier;
	return returnVector;
}

void Normalize(Vector *v, Vector *vectorOut){
	
	float vectormagnitude = sqrt((v->x*v->x) + (v->y*v->y) + (v->z*v->z));
	vectorOut->x = v->x / vectormagnitude;
	vectorOut->y = v->y / vectormagnitude;
	vectorOut->z = v->z / vectormagnitude;
	
}

float Matrix3DotProduct(const Vector* v1, Vector* v2){
	float retVal = v1->x*v2->x + v1->y*v2->y + v1->z*v2->z;
	return retVal;
}

float Matrix3DotProduct(Vector* v1, Vector* v2){
	float retVal = v1->x*v2->x + v1->y*v2->y + v1->z*v2->z;
	return retVal;
}

Vector Matrix3CrossProduct(Vector *v1, Vector *v2){
	Vector retVal;
	retVal.x = v1->y*v2->z - v2->y*v1->z;
	retVal.y = -(v1->x*v2->z - v2->x*v1->z);
	retVal.z = v1->x*v2->y - v2->x*v1->y;
	return retVal;
}

float VectorLength(const Vector &v1){
	return sqrt( v1.x*v1.x + v1.y*v1.y + v1.z*v1.z );
}

float VectorLength(Vector &v1){
	return sqrt( v1.x*v1.x + v1.y*v1.y + v1.z*v1.z );
}

Vector VectorComputeNormal(const Vector *v1, const Vector *v2,const Vector *v3){
	Vector retVal;
	float a = v1->y*(v2->z - v3->z) + v2->y*(v3->z - v1->z) + v3->y*(v1->z - v2->z);
	float b = v1->z*(v2->x - v3->x) + v2->z*(v3->x - v1->x) + v3->z*(v1->x - v2->x);
	float c = v1->x*(v2->y - v3->y) + v2->x*(v3->y - v1->y) + v3->x*(v1->y - v2->y);
	float d = v1->x*(v2->y*v3->z-v3->y*v2->z)+v2->x*(v3->y*v1->z-v1->y*v3->z)+v3->x*(v1->y*v2->z-v2->y*v1->z);
	retVal.x = a;
	retVal.y = b;
	retVal.z = c;
	return retVal;
}

Vector VectorComputeNormal(Vector *v1, Vector *v2,Vector *v3){
	Vector retVal;
	float a = v1->y*(v2->z - v3->z) + v2->y*(v3->z - v1->z) + v3->y*(v1->z - v2->z);
	float b = v1->z*(v2->x - v3->x) + v2->z*(v3->x - v1->x) + v3->z*(v1->x - v2->x);
	float c = v1->x*(v2->y - v3->y) + v2->x*(v3->y - v1->y) + v3->x*(v1->y - v2->y);
	float d = v1->x*(v2->y*v3->z-v3->y*v2->z)+v2->x*(v3->y*v1->z-v1->y*v3->z)+v3->x*(v1->y*v2->z-v2->y*v1->z);
	retVal.x = a;
	retVal.y = b;
	retVal.z = c;
	return retVal;
}

void InsertQuadToTriangleList(Vector *v1, Vector *v2, Vector *v3, Vector *v4){

}
